package com.orders.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.orders.pojo.Customer;
import com.orders.pojo.User;


public class Check {
	private static Connection conn;
	private static PreparedStatement ps;

	
	public static boolean check(Object obj){
		conn = ConnectionFactory.getConnection();
		String username = null;
		String password = null;
		ResultSet rs = null;
		
		try {
			if(obj instanceof User){
				User user = (User)obj;
				username = user.getUsername();
				password = user.getPassword();
				ps = conn.prepareStatement("select password from user where username = ?");
			}
			
			if(obj instanceof Customer){
				Customer customer = (Customer)obj;
				username = customer.getUsername();
				password = customer.getPassword();
				ps = conn.prepareStatement("select password from customer where username = ?");
			}
			
			ps.setString(1, username);
			rs = ps.executeQuery();
			while(rs.next()){
				String getpassword = rs.getString("password");
				if(getpassword.equals(password)){
					return true;
				}
			}
			return false;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return false;
	}
}
